package com.changli04._set.interview;

import java.util.HashSet;

public class HashSetDemo {

    public static void main(String[] args) {
        Person p1 = new Person("1001",19);
        Person p2 = new Person("1002",20);
        HashSet set = new HashSet();
        set.add(p1);
        set.add(p2);
        System.out.println(set); // set.size()  //2
        p1.name = "1003";


         set.remove(p1); // HashCode() 一样 但equals()不一样
         System.out.println(set);// set.size()  //2


        set.add(new Person("1003",19));  //HashCode() 不一样 可以添加
        System.out.println(set);  //set.size()  3



        set.add(new Person("1001",19)); //HashCode() 一样 equals()不一样
        System.out.println(set);//set.size() 4



    }
}
